package com.eleme.business.controller;

import com.eleme.business.dto.BusinessRegisterDTO;
import com.eleme.business.dto.BusinessUpdateDTO;
import com.eleme.business.service.BusinessService;
import com.eleme.business.vo.BusinessVO;
import com.eleme.business.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/BusinessController")
public class BusinessController {
    @Autowired
    private BusinessService businessService;

    @PostMapping("/register")
    public Result<String> register(@Validated @RequestBody BusinessRegisterDTO dto) {
        return Result.success(businessService.register(dto));
    }

    @PostMapping("/update")
    public Result<String> update(@Validated @RequestBody BusinessUpdateDTO dto) {
        return Result.success(businessService.update(dto));
    }

    @PostMapping("/status/{businessId}")
    public Result<String> changeStatus(@PathVariable String businessId, @RequestParam Integer status) {
        return Result.success(businessService.changeStatus(businessId, status));
    }

    @GetMapping("/list")
    public Result<List<BusinessVO>> listAll() {
        return Result.success(businessService.listAll());
    }

    @GetMapping("/type/{type}")
    public Result<List<BusinessVO>> listByType(@PathVariable String type) {
        return Result.success(businessService.listByType(type));
    }

    @GetMapping("/search")
    public Result<List<BusinessVO>> searchByName(@RequestParam String name) {
        return Result.success(businessService.searchByName(name));
    }

    @GetMapping("/getBusinessById/{businessId}")
    public Result<BusinessVO> getBusinessById(@PathVariable("businessId") Integer businessId) {
        return Result.success(businessService.getById(businessId.toString()));
    }

    @GetMapping("/listBusinessByOrderTypeId/{orderTypeId}")
    public Result<List<BusinessVO>> listBusinessByOrderTypeId(@PathVariable("orderTypeId") Integer orderTypeId) {
        return Result.success(businessService.listByType(orderTypeId.toString()));
    }
} 